package com.ftf.tp.blog.application.dto.command;

import com.ftf.tp.blog.application.assembler.QuestionAssembler;
import com.ftf.tp.blog.application.assembler.TagAssembler;
import com.ftf.tp.blog.application.dto.TagDTO;
import com.ftf.tp.blog.domain.configuration.aggregate.QuestionAgg;
import com.ftf.tp.common.core.utils.BeanConverter;
import com.ftf.tp.common.core.utils.ConverterUtil;
import com.ftf.tp.common.core.utils.SnowIdUtils;
import com.ftf.tp.common.cqrs.annotation.Command;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.List;


/**
 * @author tanghao
 * @date 2022/8/11
 */
@Data
@Command
public class QuestionCommand implements Serializable, BeanConverter<QuestionAgg> {

    private Long id;

    /**
     * 问题标题
     */
    @NotEmpty(message = "请输入你的问题")
    @ApiModelProperty("问题标题")
    private String questionTitle;

    /**
     * 问题描述
     */
    @ApiModelProperty("问题描述")
    private String questionDescribe;

    /**
     * 提问人id
     */
    @NotNull(message = "系统有误")
    @ApiModelProperty("提问人id")
    private Long askerId;

    /**
     * 提问人名称
     */
    @NotEmpty(message = "系统有误")
    @ApiModelProperty("提问人名称")
    private Long askerName;

    /**
     * 关联标签
     */
    @ApiModelProperty("关联标签")
    private List<TagDTO> tagDTOList;

    /**
     * 转换接口方法
     *
     * @return T
     */
    @Override
    public QuestionAgg doForward() {
        QuestionAgg questionAgg = new QuestionAgg();
        ConverterUtil.copyPropertiesIgnoreNull(this,questionAgg);
        questionAgg.setId(SnowIdUtils.uniqueLong());
        questionAgg.setSupportNums(0);
        questionAgg.setAnswerNums(0);
        questionAgg.setFocusNums(0);
        questionAgg.setHotNums(0);
        questionAgg.setTagValues(QuestionAssembler.INSTANCE.dtoToValue(tagDTOList));
        return questionAgg;
    }
}
